import datetime
import time
class Point:
    def __init__(self,x,y):
        self.x = x
        self.y = y

    def __repr__(self):
        return "<{}> x:{} y:{}".format(__class__.__name__,self.x,self.y)
    __str__ = __repr__

    def __add__(self, other):
        time.sleep(2)
        newPoint = Point(self.x+other.x,self.y+other.y)
        print(repr(newPoint))
        return newPoint

class Timeit:
    def __enter__(self):
        self.start = datetime.datetime.now()
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        delta = (datetime.datetime.now() - self.start).total_seconds()
        print("Point took {}s".format(delta))

p1 = Point(6,8)
p2 = Point(7,9)

with Timeit():
    p1 + p2

"""
不用point方法，只实现具有上下文管理的类试下
"""
